package com.woniuxy.service.impl;

import com.woniuxy.entity.DTO.ShopProductsDTO;
import com.woniuxy.entity.ShopProducts;
import com.woniuxy.dao.ShopProductsDao;
import com.woniuxy.service.ShopProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.List;


/**
 * (ShopProducts)表服务实现类
 *
 * @author makejava
 * @since 2025-07-10 11:54:17
 */
@Service("shopProductsService")
public class ShopProductsServiceImpl implements ShopProductsService {
    @Autowired
    private ShopProductsDao shopProductsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ShopProducts queryById(Long id) {
        return this.shopProductsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param shopProducts 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShopProducts> queryByPage(ShopProducts shopProducts, PageRequest pageRequest) {
        long total = this.shopProductsDao.count(shopProducts);
        return new PageImpl<>(this.shopProductsDao.queryAllByLimit(shopProducts, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shopProducts 实例对象
     * @return 实例对象
     */
    @Override
    public ShopProducts insert(ShopProducts shopProducts) {
        this.shopProductsDao.insert(shopProducts);
        return shopProducts;
    }

    /**
     * 修改数据
     *
     * @param shopProducts 实例对象
     * @return 实例对象
     */
    @Override
    public ShopProducts update(ShopProducts shopProducts) {
        this.shopProductsDao.update(shopProducts);
        return this.queryById(shopProducts.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.shopProductsDao.deleteById(id) > 0;
    }

    @Override
    public List<ShopProducts> queryHotSalesById(Integer id) {
        return shopProductsDao.queryHotSalesById(id);
    }
    @Override
    public List<ShopProductsDTO> queryKillSalesById(Integer id) {
        return shopProductsDao.queryKillSalesById(id);
    }

    @Override
    public List<ShopProducts> findAll() {
        return shopProductsDao.findAll();
    }
}
